﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace DM
{
    public partial class tour_dates : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public string GetName(string name, char separator)
        {
                string[] parts = name.Split(separator);
                string retorno = "";
                for (int i = 0; i < parts.Length - 1; i++)
                    retorno += parts[i] + separator.ToString();

                return retorno;
        }

        //clique do botao de busca arquivos
        protected void btnSearchFiles_Click(object sender, EventArgs e)
        {
            string pathFile = GetName(FileUpload.PostedFile.FileName, '\\');

            //string pathFile = "C:\\ADEMS_FILES\\" + "\\MoviesLegendFiles";
            string html = @"<table class=""dates"" cellpadding=""0"" cellspacing=""0"" border=""0"">
                            <tr class=""thead"">
                              <td class=""col1"">Date / Venue</td>
                              <td class=""col2"">Location</td>
                              <td class=""col3"">Information</td>
                            </tr>";

            DirectoryInfo pasta = new DirectoryInfo(pathFile);
            FileInfo[] arquivos = pasta.GetFiles();

            int count = 0;
            foreach (FileInfo file in arquivos)
            {
                string[] parts = file.Name.Split('.');
                if (parts[parts.Length - 1] == "mp3")
                {
                    string name = "";
                    for (int i = 0; i < parts.Length - 1; i++)
                        name += parts[i];

                    string color = "";
                    if (count % 2 == 0)
                    {
                        color = @"class=""even""";
                    }

                    html += @"<tr "+color+@">
                              <td class=""col1"">" + file.LastWriteTime.ToString() + @"<br>
                                <a href=""#"" class=""name"">" + name + @"</a><br>
                                <a href=""#"" class=""facebook-event"">Compartilhar</a></td>
                              <td>"+ file.Length.ToString() + @"<br>
                                " + file.Extension + @"</td>
                              <td>"+file.DirectoryName +@"</td>
                            </tr>";
                    count++;
                }
            }
            html += "</table>";
            dv_tb_files.InnerHtml = html;
        }
    }
}